package com.java1412.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author java1412
 * @since 2023-06-06 15:49:37
 */
@Service
public class HelloService {

    private final static String INSTANCE_URL = "http://SERVICE-HI";

    @Resource
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")// 指定兜底方案
    public String hiService(String name) {
        return restTemplate.getForObject(INSTANCE_URL + "/hi?name=" + name, String.class);
    }

    public String hiError(String name) {
        // 直接返回一个字符串
        return "hi," + name + ", sorry,error!";
    }
}
